<?php
    require_once dirname(__FILE__) . '/shared/config/config.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_affiliate.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_bet_history.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_bet_calculators.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_tran_history.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_matches.php';
    require_once DOCUMENT_ROOT . DIR_SHARED_API . 'api_choice.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'check_user_login.php';
    require_once DOCUMENT_ROOT . DIR_INCLUDE . 'html_generator.php';
    $title = 'Cashier';

    $user = $_SESSION['user_info'];
    $list_bet_history = NULL;
    $list_tran_history = NULL;

    $result = filter_input(INPUT_GET, 'result');
    
    $type = filter_input(INPUT_GET, 't');
    if ($type == 'bet') {
        $list_bet_history = api_bet_history::get_bet_history_of_user($user[0]);
    } elseif ($type == 'tran') {
        $list_tran_history = api_tran_history::get_tran_history_of_user($user[0]);
    }
?>

<!DOCTYPE html>
<!-- IE SECTION -->

<!--[if lt IE 7]>
<html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>
<html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>
<html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js"> <!--<![endif]-->

                     <!-- END IE SECTION -->
<html>
<head>
    <?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'head.php' ?>
    <script type="text/javascript">
        var cashierDeposit = new CashierDeposit('<?php echo $user['balance']; ?>');
        $(document).ready(function() {
            cashierDeposit.monitorRadioMethod(
                    "input[name='method']", 
                    "#deposit_gcList",
                    "#deposit_paypal_referenceList",
                    "#deposit_moneybookers_onetapList");
            cashierDeposit.monitorTxtDepositAmount(
                    "#depositAmount", 
                    ".totalamount",
                    "#balance_after_deposit");
            cashierDeposit.monitorBtnDepositMoney(
                    "#btn_next_id",
                    "<?php echo LINK_ROOT . DIR_AJAX; ?>payment_form.php",
                    "#content",
                    "input[name='method']:checked",
                    "#depositAmount");
        });
    </script>
</head>
<body>
<?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'header.php' ?>
<!-- Title -->
<div class="section section-black">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="calltoaction-wrapper">
                    <h3>Cashier</h3>
                    
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Title -->

<!-- Detail -->
<div class="section">
    <div class="container">
        <div class="row">
            <div class="col-md-3">
                <div class="service-wrapper">
                    <div class="row">
                        <ul class="nav nav-stacked text-left">
                            <li><a href="?t=tran">Transaction History</a></li>
                            <li><a href="?t=bet">Betting History</a></li>
                            <li><a href="?t=deposit">Deposit Money</a></li>
                            <li><a href="?t=withdraw">Withdraw Money</a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="col-md-9">
                <div class="service-wrapper">
                    <div id="content" class="row">
                        <?php
                            if ($type == 'bet') {
                                show_table_bet_history($list_bet_history);
                            } elseif ($type == 'tran') {
                                show_table_tran_history($list_tran_history);
                            } elseif ($type == 'deposit') {
                                if ($result === "success") {
                                    show_modal_message("Payment successfully.");
                                } else if ($result === "cancel") {
                                    show_modal_message("Payment canceled.");
                                }
                                show_deposit_option();
                            } elseif ($type == 'withdraw') {
                                show_table_bet_history($list_tran_history);
                            } else {
                                ?>
                                <h1>Welcome to Cashier Page!</h1>
                            <?php
                            }
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End Detail -->

<?php require_once DOCUMENT_ROOT . DIR_INCLUDE . 'footer.php' ?>
</body>
</html>